﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SaaSKit.Taskr.Service;
using root.Proxies;
using System.ServiceModel;

namespace root.Controllers
{
    public class CustomizeController : BaseController
    {
        //
        // GET: /Customize/

        public ActionResult Index()
        {            
            return View();
        }

        //
        // POST: /Customize/Update

        public ActionResult Update(string logoUrl, string customStatuses, string customCss)
        {

            bool faulted = false;
            try
            {
                SettingsDTO settings = new SettingsDTO()
                {
                    CustomLogoUrl = !string.IsNullOrEmpty(logoUrl) ? new Uri(logoUrl) : null,
                    CustomStatuses = !string.IsNullOrEmpty(customStatuses) ? customStatuses : null,
                    CustomStyle = !string.IsNullOrEmpty(customCss) ? customCss : null
                };

                AdminServiceProxy proxy = new AdminServiceProxy();
                proxy.UpdateSettings(settings);
                
            }
            catch (FaultException<ApplicationFaultDetail> fault)
            {
                ViewData["ErrorMsg"] = fault.Detail.EndUserMessage;                
            }
            catch (Exception e)
            {
                ViewData["ErrorMsg"] = "An unknown error occurred.";                
            }

            return RedirectToAction("Index");
           
        }

    }
}
